<template>
  <div>
  <div class="big-box">
    <div class="img-box">
      <div
        class="show-box"
        :style="{
          transform: 'translateX(' + translate + 'px)',
          transition: tsion ? 'all 0.5s' : 'none',
        }"
      >
        <img src="../assets/images/1.png" alt="" />
        <img v-for="item in src" :key="item" :src="item.img" alt="" />
        <img src="../assets/images/2.png" alt="" />
      </div>
    </div>
    <div class="arrowhead-box" ref="swiper">
      <span @click="last"><img src="../assets/images/last.png" alt="" style="height:50px ;width:50px"></span>
      <span @click="next"><img src="../assets/images/last.png" alt="" style="height:50px ;width:50px"></span>
    </div>
    <div class="swiper-boxs" ref="swiper">
      <span v-for="item in src" :key="item"></span>
    </div>
  </div>
  <div class="Newsbox"> 
    <el-card class="newshead">
      新闻动态
    </el-card>
    <div class="big-box2">
    <div class="img-box">
      <div
        class="show-box"
        :style="{
          transform: 'translateX(' + translate + 'px)',
          transition: tsion ? 'all 0.5s' : 'none',
        }"
      >
        <img src="../assets/images/1.png" alt="" />
        <img v-for="item in src2" :key="item" :src="item.img" alt="" style="height:auto ;width:100%"/>
        <img src="../assets/images/2.png" alt="" />
      </div>
    </div>
    <div class="arrowhead-box" ref="swiper">
      <span @click="last"><img src="../assets/images/last.png" alt="" style="height:50px ;width:50px"></span>
      <span @click="next"><img src="../assets/images/last.png" alt="" style="height:50px ;width:50px"></span>
    </div>
    <div class="swiper-boxs" ref="swiper">
      <span v-for="item in src2" :key="item"></span>
    </div>
  </div>
    <el-card class="news">
      <div class="new" @click="new1">
        <p>偷电司机被抓！上海警方破获充电站偷漏电案!</p>
        <p class="time">2024-04-07</p>
      </div>
     <el-divider></el-divider>
     <div class="new" @click="new2">
        <p>电工因盗窃电力设施被刑拘！</p>
        <p class="time">2023-12-28</p>
      </div>
      <el-divider></el-divider>
      <div class="new" @click="new3">
        <p>独居老人一个月电费多出50多元,电力网格员上门发现“偷电贼”隐身墙内！</p>
        <p class="time">2024-01-28</p>
      </div>
      <el-divider></el-divider>
      <div class="new" @click="new4">
        <p>国网宁波供电公司：三次上门排查破解用户漏电之谜！</p>
        <p class="time">2021-08-18</p>
      </div>
      <el-divider></el-divider>
      <div class="new" @click="new5">
        <p>河南女子1个月仅用10度电被指偷电，罚款4万元！</p>
        <p class="time">2023-10-25</p>
      </div>
      <el-divider></el-divider>
      <div class="new" @click="new6">
        <p> 供电部门放“白猫”！贵阳一小区17户居民偷电近30万度！</p>
        <p class="time">2020-12-16</p>
      </div>
    </el-card>
  </div>
</div>
</template>
 
<script>
export default {
  name: "HomeView",
  data() {
    return {
      src: [
        { img: require("../assets/images/1.png") },
        { img: require("../assets/images/2.png") },
        { img: require("../assets/images/3.png") },
        { img: require("../assets/images/4.jpeg") },
        { img: require("../assets/images/5.png") },
      ],
      src2: [
        { img: require("../assets/images/new1.png") },
        { img: require("../assets/images/new2.jpg") },
        { img: require("../assets/images/new3.png") },
        { img: require("../assets/images/new4.jpg") },
        { img: require("../assets/images/new5.png") },
        { img: require("../assets/images/new6.png") }
      ],
      translateX: 0,
      tsion: true,
    };
  },
  methods: {
    last() {
      this.translateX--;
      this.tsion = true;
      if (this.translateX < 0) {
        setTimeout(() => {
          this.tsion = false;
          this.translateX = this.src.length - 1;
        }, 500);
      }
    },
    next() {
      this.translateX++;
      this.tsion = true;
      if (this.translateX > this.src.length - 1) {
        setTimeout(() => {
          this.tsion = false;
          this.translateX = 0;
        }, 500);
      }
    },
    swiper(i) {
      this.translateX = i;
    },
    new1(){
      this.$router.push("/new1")
    },
    new2(){
      this.$router.push("/new2")
    },
    new3(){
      this.$router.push("/new3")
    },
    new4(){
      this.$router.push("/new4")
    },
    new5(){
      this.$router.push("/new5")
    },
    new6(){
      this.$router.push("/new6")
    }
  },
  mounted() {
    setInterval(() => {
      this.next();
    }, 3000);
  },
  computed: {
    translate() {
      return -(this.translateX + 1) * 1050;
    },
  },
  watch: {
    translateX: {
      handler(val) {
        let a = this.$refs.swiper.querySelectorAll("span");
        a.forEach((element) => {
          element.style.width = "12px";
        });
        if (this.translateX < 0) {
          val = this.src.length - 1;
        }
        if (this.translateX > this.src.length - 1) {
          val = 0;
        }
        a[val].style.width = "100px";
      },
    },
  },
};
</script>
  <style lang="less" scoped>
.Newsbox{
  .newshead{
    position: relative;
    margin-left: 16%;
    width: 1050px;
    height: 60px;
    font-weight: 700;
    font-family: STXingkai;
    font-size: 28px;
    text-align: center;
  }

  .news{
    position: relative;
    margin-left: 770px;
    width: 520px;
    height: 550px;
    margin-top: -650px;
    .new{
      cursor: pointer;
      .time{
        color: #999;
        line-height: 100%;
        margin: 5px;
      }
    }
  }
}

body {
  margin: 0;
  padding: 0;
  background-image: linear-gradient(to top, #37ecba 0%, #72afd3 100%);
}
span {
  margin: 0;
  padding: 0;
}

.big-box {
  width: 1050px;
  height: 400px;
  background-color: #999;
  margin: 10px auto;
  /* position: fixed;
  top: 22%;
  left: 15%; */
  position: relative;
  margin-top: 1.6%;
  margin-left: 16%;
  box-shadow: 0 0 3pc rgb(0, 0, 0, 0.4);
}

.big-box2 {
  width: 500px;
  height: 550px;
  background-color: #999;
  margin: 10px auto;
  /* position: fixed;
  top: 22%;
  left: 15%; */
  position: relative;
  margin-top: 1.6%;
  margin-left: 16%;
  margin-bottom: 100px;
  box-shadow: 0 0 3pc rgb(0, 0, 0, 0.4);
}

.img-box {
  overflow: hidden;
  height: 100%;
  width: 100%;
}
.show-box {
  display: flex;
  height: 100%;
  width: 100%;
  transition: all 0.5s;
}
.show-box img {
  float: left;
  min-width: 1050px;
  min-height: 400px;
}
.arrowhead-box {
  position: absolute;
  top: 40%;
  float: left;
  width: 100%;
  height: 50px;
}
.arrowhead-box span {
  float: left;
  display: block;
  height: 60px;
  border-radius: 50px;
  /* background: url("../assets/img/banner2.jpg") no-repeat; */
  /* background-color: rgb(0, 0, 0, 0.4); */
  background-position: 6px 14px;
  cursor: pointer;
  opacity: 0.5;
}
.arrowhead-box span:nth-child(2) {
  float: right;
  transform: rotate(180deg);
}
.arrowhead-box span:hover {
  opacity: 1;
}
.swiper-boxs {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
 
}
.swiper-boxs span {
  float: left;
  width: 12px;
  height: 12px;
  background-color: white;
  border-radius: 50px;
  margin-left: 10px;
  cursor: pointer;
  transition: all 0.5s;
}
.swiper-boxs span:nth-child(1) {
  width: 100px;
}
</style>